<!--
@name:prescriptionList
@author:Zhenglei
@date:16:46
@description:prescriptionList
@update:2022/5/1116:46
-->
<template>
  <div class="pd-20">
    <element-table class="mt-20"
                   :columns="columns"
                   :data="tableData"
                   v-loading="loading"
                   pager
                   :pageTotal="pageTotal"
                   :pageIndex="pageIndex"
                   :pageSize="pageSize"
                   @handleChangePage="handleChangePage">
      <template v-slot:status="{row}">
        <el-tag type="primary"
                   v-if="row.status==1">待转换</el-tag>
        <el-tag type="danger"
                   v-if="row.status==4">审核被拒绝</el-tag>
      </template>
      <template v-slot:option="{row}">
        <el-button type="primary"
                   v-if="row.status==1"
                   @click="handleOption('transition', row)">去转换
        </el-button>
        <el-button type="info"
                   v-if="row.status==4"
                   @click="handleOption('edit', row)">编辑
        </el-button>
      </template>
    </element-table>

    <detail-dialog :dataObj="dataObj"
                   v-if="showDialog"
                   :visible.sync="showDialog"/>
  </div>
</template>

<script>
import ElementTable from "../../../../base/ElementTable";
import detailDialog from "./detailDialog";

export default {
  name: "prescriptionList",
  data() {
    return {
      loading: false,
      pageTotal: 0,
      pageSize: 20,
      pageIndex: 1,
      tableData: [],
      dataObj: {},
      showDialog: false,
      columns: [
        {
          label: '管理对象',
          prop: 'userName',
          align: "center",
        }, {
          label: '上传时间',
          prop: 'uploadTime',
          align: "center",
          formatter: (row, cellValue) => {
            return this.formatterDate(row.uploadTime)
          },
        }, {
          label: '转换状态',
          prop: 'status',
          align: "center",
          isSlot: true

        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
          width: 200
        }
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleOption(op, row) {
      switch (op) {
        case 'edit':
          this.showDialog = true
          this.dataObj=row
          this.dataObj.optionType='edit'
          break
        case 'transition':
          this.showDialog = true
          this.dataObj=row
          this.dataObj.optionType='transition'
          break
      }
    },
    getList() {
      this.loading = true
      this.post(this.api.slowDisease.getTransformList, {
        pageSize: this.pageSize,
        pageIndex: this.pageIndex - 1,
      }).then((res) => {
        this.loading = false
        if (res.data.code === '200') {
          this.tableData = res.data.object
          this.pageTotal = res.data.totalNum;
        }
      })
    },
    // 时间转换
    formatterDate(time) {
      if (time)
        return this.commonFunction.timestampFormat(new Date(time), 'yyyy-MM-dd hh:mm')
      else
        return ''
    },
    // 分页
    handleChangePage(page) {
      this.pageIndex = page;
      this.getList();
    },
  },
  components: {
    'element-table': ElementTable,
    'detail-dialog': detailDialog
  },
}
</script>

<style scoped>

</style>
